#include "stdafx.h"
#include "AppConfigClient.h"
#include "tinyxml.h"

	CAppConfigClient::CAppConfigClient( const TCHAR* filename )
		: Singleton()
	{
		//MessageBoxA( NULL, filename, filename, 0 );
		std::cout << filename << std::endl << std::endl;
		Parse( filename );
	}

	bool CAppConfigClient::Parse( const TCHAR* filename )
	{
		TCHAR name[128] = "";
		GetCurrentDirectoryA( 128, name );
		TiXmlDocument *pXml = new TiXmlDocument( filename );
		if( pXml->LoadFile() )
		{
			TiXmlElement *Root = pXml->RootElement();
			TiXmlNode *Element = NULL;
			std::string name = "";
			std::string value = "";

			for( Element = Root->FirstChild(); Element; Element = Root->NextSibling() )
			{
				const TiXmlElement *box = (const TiXmlElement*)Element;
				for( const TiXmlNode *sub_tag = box->FirstChild(); sub_tag; sub_tag = sub_tag->NextSibling() )
				{
					const TiXmlElement *sub_element = (const TiXmlElement*)sub_tag;
					name = sub_element->Value();
					const TiXmlNode *IDAttribute = sub_element->FirstChild();
					value = IDAttribute->Value();
					mConfigInfo[name] = value;
				}
			}
			Safe_Delete( pXml );
			return true;
		}
		return false;
	}
		
	CAppConfigClient::~CAppConfigClient( void )
	{
		mConfigInfo.clear();
	}

	UINT32 CAppConfigClient::GetWindowWidth()
	{
		InfoMap::iterator iter = mConfigInfo.find(TEXT("width"));
		m_iWndWidth  = atoi( (iter->second).c_str() );
		return m_iWndWidth;
	}

	UINT32 CAppConfigClient::GetWindowHeight()
	{
		InfoMap::iterator iter = mConfigInfo.find(TEXT("height"));
		m_iWndHeight = atoi( (iter->second).c_str() );
		return m_iWndHeight;
	}

	UINT32 CAppConfigClient::GetShaderType()
	{
		InfoMap::iterator iter = mConfigInfo.find(TEXT("ShadingType"));
		return atoi( (iter->second).c_str() );
	}

	bool CAppConfigClient::IsFullScene()
	{
		InfoMap::iterator iter = mConfigInfo.find( TEXT("fullsrceen") ); 
		return bool( 1 == atoi((iter->second).c_str() ) );
	}

	bool CAppConfigClient::IsUseNVPerfHUD()
	{
		InfoMap::iterator iter = mConfigInfo.find(TEXT("UseNVPerfHUD"));
		return bool( 1 == atoi((iter->second).c_str() ) );
	}

	UINT32 CAppConfigClient::GetFrameCycTimer()
	{
		InfoMap::iterator iter = mConfigInfo.find(TEXT("FrameCycTimer"));
		return atoi((iter->second).c_str() );
	}

	UINT32 CAppConfigClient::GetRenderMgrOrder(const String& MgrName)
	{
		InfoMap::iterator iter = mConfigInfo.find( MgrName ); 
		return atoi((iter->second).c_str() );
	}

	InfoMap& CAppConfigClient::getInfoMap()
	{
		return mConfigInfo;
	}

	String CAppConfigClient::GetResPath( const String& ResType )
	{
		return getSingletonPtr()->mConfigInfo[ResType];	
	}
